import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author ZYJ
 * @date 2021年09月24日 14:36
 */
public class HashMapTest {
    public static void main(String[] args) {
        HashMapThread thread0 = new HashMapThread();
        HashMapThread thread1 = new HashMapThread();
        HashMapThread thread2 = new HashMapThread();
        HashMapThread thread3 = new HashMapThread();
        HashMapThread thread4 = new HashMapThread();
        thread0.start();
        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
    }
}

class HashMapThread extends Thread {
    /**
     * 一百万
     */
    private static final int num = 1000000;
    /**
     * 定义一个原子整型类
     */
    private static AtomicInteger ai =new AtomicInteger();
    /**
     * 定义一个hashmap，用于存放整数
     */
    private static Map<Integer, Integer> map =new HashMap<>();

    @Override
    public void run() {
        while (ai.get() <= num) {
            map.put(ai.get(), ai.get());
            ai.incrementAndGet();
        }
    }
}